// 粉饼干
function cake(m, n) {
    m = m.sort((a, b) => a - b);
    n = n.sort((a, b) => a - b);
    let index = 0;
    let num = 0;
    for (let i = 0; i < m.length; i++) {
        if (i <= n.length && m[i] > n[index]) {
            index++;
            num++
        }
    }
    return num;
}
// 摆动序列
function wing(arr) {
    let prediff = arr[0] - arr[1];
    let count = prediff == 0 ? 0 : 2;
    for (let i = 2; i < arr.length; i++) {
        let curdiff = arr[i] - arr[i + 1];
        if ((prediff > 0 && curdiff < 0) || (prediff < 0 && prediff > 0)) {
            count++;
            prediff = curdiff;
        }
    }
    return count;
}

// 移除k个数字
function moveK(num, k) {
    // 循环生成数组，判断是否是大数字 前置数大删除前置数
    let stack = [];
    for (let val of num) {
        while (k && num.length && stack[stack.length - 1] > val) {
            stack.pop();
            k--;
        }
        stack.push(val)
    }
    let res = stack.join("");
    // 除去前置0
    if (res == 0) return "0";
    while (stack[0] == 0) {
        stack.shift()
    }
    // 若没有k--
    return stack.join("").substring(0, stack.length - k)
}

// 跳跃游戏
// 当前步数
function jump(arr) {
    let preMaxStep = 0;
    for (let i = 0; i < arr.length; i++) {
        if (preMaxStep < 1) return false;
        preMaxStep = Math.max(preMaxStep, arr[i] + i);
        if (preMaxStep > arr.length) return true
    }
}

// 射击气球
function shot(arrs) {
    arrs = arrs.sort((a, b) => a[0] - b[0]);
    let count = 0;
    let end = arrs[0][1]
    for (let i = 0; i < arr.length; i++) {
        if (end < arr[i][1]) {
            count++;
            end = arr[i][1]
        }
    }
    return count
}